<template>
  <div>
    <a-modal title="权限组开关" :visible="visible" @before-open="open" @before-ok="handleOk" @cancel="handleCancel" :align-center="false" title-align="start" width="500px" :mask-closable="false">
      <div>
        <a-form auto-label-width ref="formRef" size="medium" :model="form" :rules="rules">
          <a-space direction="vertical" :size="24">
            <a-radio-group v-model="form.enable">
              <a-radio :value="true">开启</a-radio>
              <a-radio :value="false">关闭</a-radio>
            </a-radio-group>
          </a-space>
        </a-form>
      </div>

      <template #footer>
        <a-button class="gray-outline" @click="handleCancel">取消</a-button>
        <a-button type="primary" :loading="loading" @click="handleOk">确定</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRefs, computed } from 'vue'
  import { findWarehouseListByParam } from '@/api/warehouse'
  import { updatePackageWarehouse } from '@/api/order'
  import { updateEnable } from '@/api/system'
  import { Message } from '@arco-design/web-vue'
  import _ from 'lodash-es'
  export default defineComponent({
    props: ['ids'],
    setup(props: any, { emit }) {
      let visible = ref(false)
      const formRef = ref()
      const data: any = reactive({
        form: {
          enable: true,
        },
        loading: false,
      })

      const open = () => {}
      const handleOk = () => {
        formRef.value.validate(async (valid: any) => {
          if (!valid) {
            let params = {
              enable: data.form.enable,
              idList: props.ids,
            }
            data.loading = true
            const res: any = await updateEnable(params)
            if (res.code == 'SUCCESS') {
              // data.form = {}
              data.form.enable ? Message.success('已启用') : Message.success('已禁用')
              visible.value = false
              emit('save')
            }
            data.loading = false
          }
        })
      }

      const handleCancel = () => {
        formRef.value.clearValidate()
        formRef.value.resetFields()
        visible.value = false
      }
      return {
        ...(toRefs(data) as any),
        visible,
        formRef,
        open,
        handleOk,
        handleCancel,
      }
    },
  })
</script>

<style lang="less" scoped></style>
